<?php
	ob_start();
	session_start();
    require("../lib/config.php");
	require("../lib/database.php");
	require("lib/nguoidung.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Login</title>
	<link href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet" />
	<!-- bootstrap JavaScript -->
	<script type="text/javascript" src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
	<!--custom css-->
	<link rel="stylesheet" type="text/css" href="css/style.css">
	<script language="javascript">
		function checklog()
		{
			if(document.frmlog.username.value == ""){
				alert("Vui lòng điền tên đăng nhập!");
				document.frmlog.username.focus();
				return false;
			}
			if(document.frmlog.password.value == ""){
				alert("Vui lòng điền mật khẩu!");
				document.frmlog.password.focus();
				return false;
			}else{
				return true;
			}
		}
	</script>
</head>
<body>
	<div class="container">
		<div class="row">
			<div class="col-md-12">
				<h2>ĐĂNG NHẬP</h2>
			</div>
		</div><!--/end row-->

			<div class="row">
			
				<div class="col-md-4"></div>

				<div class="col-md-4">
					<div class="panel panel-primary">
					
					<div class="panel-heading">Đăng nhập hệ thống</div>
						<div class="panel-body">
							<form action="login.php" method="post" name="frmlog">
								<div class="input-group">
									<span class="input-group-addon">Username</span>
									<input type="text" name="username" class="form-control" placeholder="Username" id="username">
								</div>
								<div class="input-group">
									<span class="input-group-addon">Password</span>
									<input type="password" name="password" class="form-control" id="password" placeholder="Password">
								</div>
								<?php
									if(isset($_POST['login']))
									{
										$user = $_POST['username'];
										$pass = $_POST['password'];
										$db = new libraries_user;
										$data = $db->check_login($user,$pass);
										if($data == FALSE){
											echo "<span style='color:#F00'>Tài khoản không hợp lệ</span>";
										}else
										{
											$id=$data['mand'];
											$value=$db->getdata($id);
											$_SESSION['ses_userid'] = $value['mand'];
											$_SESSION['ses_name']=$value['ten'];
											$_SESSION['ses_user'] = $value['username'];
											$_SESSION['ses_level'] = $value['mapq'];
											header("location:index.php");
											die();
										}					
									} 
								?>
								<center>
									<button type="submit" name="login" class="btn btn-default">Đăng nhập</button>
								</center>
							</form>
						</div>
					</div>
				</div>
				<!--End .panel panel-primary-->
			</div>
			<!--end .col-md-8-->

			<div class="col-md-4"></div>

		</div><!--end row-->

		<div id="footer">
			<div class="row">
				<div class="col-md-12">
					<span class="label label-success">Đăng nhập</span>
				</div>
			</div>
		</div><!--End footer-->
	</div>
</body>
</html>